<?php
class MapsController extends Zend_Controller_Action {
	public function indexAction() {
		$gameProperties = Zend_Registry::get('GameProperties');
		$this->view->assign('gameProperties', $gameProperties);
		
		$mTiles = new Application_Model_Tiles();
		$dTiles = $mTiles->findall(
			array(
				'x >= ?' => 1,
				'x <= ?' => $gameProperties->mapsSizeX,
				'y >= ?' => 1,
				'y <= ?' => $gameProperties->mapsSizeY,				
			), 
			array('TileTypes', 'TileResources', 'TileObjects')
		);
		
		$dViewTiles = array();
		foreach($dTiles as $dTile) {
			$viewTileId								= $dTile->x . 'x' . $dTile->y;
			$dViewTiles[$viewTileId]	= $dTile;
		}
		$this->view->assign('tiles', $dViewTiles);
	}
	
	public function tileresourceAction() {
		$model	= new Application_Model_TileResources();
		$where	= array(
			'tile_resources.resources_id = ?'	=> (int) $this->getRequest()->getParam('resourceId'),
			'tile_resources.tiles_id = ?'			=> (int) $this->getRequest()->getParam('tileId')
		);
		
		if(is_object($resource	= $model->find($where, array('Resources', 'Actions')))) {
			$this->view->assign('tileId', (int) $this->getRequest()->getParam('tileId'));
			$this->view->assign('data', $resource);			
		}
	}	
}
?>